﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Policy;
using MS_UI;

namespace LQB
{
    public partial class LQB : UserControl
    {
       
        public LQB()
        {
            InitializeComponent();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);
            mytimer = new Timer();
            mytimer.Interval = 10;
            mytimer.Tick += Mytimer_Tick;
            mytimer.Enabled = true;

        }

        private void Mytimer_Tick(object sender, EventArgs e)
        {
            if (this.DeviceStateName != null)
            {
                if (CommonMethod.CurrentValue != null && CommonMethod.CurrentValue.ContainsKey(this.DeviceStateName))
                {
                    Start = CommonMethod.CurrentValue[DeviceStateName] == "1" ? true : false;
                }
            }
            if (Start)
            {
                if (this.index < this.indexMax)
                {
                    this.index++;
                }
                else
                {
                    this.index = 0;
                }
            }
            this.change();
            recMemory.ClearMemory(); 
        }

        private void change() 
        {
            switch (this.index)
            {
                case 0:
                    this.MainPic.Image = MS_UI.Properties.Resources._1;
                    break;
                case 1:
                    this.MainPic.Image = MS_UI.Properties.Resources._2;
                    break;
                case 2:
                    this.MainPic.Image = MS_UI.Properties.Resources._3;
                    break;
                case 3:
                    this.MainPic.Image = MS_UI.Properties.Resources._4;
                    break;
                case 4:
                    this.MainPic.Image = MS_UI.Properties.Resources._5;
                    break;
                case 5:
                    this.MainPic.Image = MS_UI.Properties.Resources._6;
                    break;
                case 6:
                    this.MainPic.Image = MS_UI.Properties.Resources._7;
                    break;
                case 7:
                    this.MainPic.Image = MS_UI.Properties.Resources._8;
                    break;
                case 8:
                    this.MainPic.Image = MS_UI.Properties.Resources._9;
                    break;
                case 9:
                    this.MainPic.Image = MS_UI.Properties.Resources._10;
                    break;
                case 10:
                    this.MainPic.Image = MS_UI.Properties.Resources._11;
                    break;
                default:
                    this.MainPic.Image = MS_UI.Properties.Resources._1;
                    break;
            }
        }
        //当前选择的图片序号
        private int index;

        // 定义一个计时器
        private Timer mytimer;

        // 定义计时器的时间间隔
        private int interval = 10;
        public int Interval
        {
            get { return interval; }
            set
            {
                if (mytimer.Interval != value)
                {
                    mytimer.Interval = value;
                }
            }
        }

        // 定义控件的转动属性
        private bool start = true;
        public bool Start
        {
            get
            {
                return start;
            }
            set
            {
                start = value;
            }
        }

        // 定义设备状态变量
        public string DeviceStateName { get; set; }
        // 定义设备启动变量
        public string DeviceStartName { get; set; }
        // 定义设备停止变量
        public string DeviceStopName { get; set; }
        // 定义设备名称
        public string DeviceName { get; set; }


        // 最大图片数目
        private int indexMax = 11;
        public int IndexMax
        {
            get
            {
                return indexMax;
            }
            set
            {
                indexMax = value;
            }
        }
        public delegate void PumpClickDelegate(object sender, EventArgs e);


        public event PumpClickDelegate UserControlClick;


        private void MainPic_DoubleClick(object sender, EventArgs e)
        {
            if (UserControlClick != null)
            {
                UserControlClick(sender, new EventArgs());
            }
        }
    }
}
